package com.feicheng.controller.main.admin.client;


import com.alibaba.fastjson.JSONObject;
import com.feicheng.common.result.ResultInfo;
import com.feicheng.persistence.entity.CardType;
import com.feicheng.service.impl.FClientServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author cailongyang
 * @since 2021-12-02
 */
@RestController("/main/admin/client/card-type")
@RequestMapping("/main/admin/client/card-type")
public class CardTypeController {
//    @Resource(name = "client-service")
//    Map<String, IClientService>
    @Autowired
    FClientServiceImpl fClientService;

    /**
     * 分页查询
     * @param name
     * @param statu
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("/list")
    public ResultInfo getCardTypeList(
            String name,
            Boolean statu,
            @RequestParam(required = false,defaultValue = "1") Integer currentPage,
            @RequestParam(required = false,defaultValue = "5") Integer pageSize
    ) {
        CardType cardType = new CardType();
        cardType.setName(name);
        cardType.setStatu(statu);
//        return ResultInfo.success(fClientService.getCardTypesByPage(cardType,current,size));
        return fClientService.getCardTypesByPage(cardType,currentPage,pageSize);
    }

    /**
     * 根据会员卡id查详情
     * @param cardTypeId
     * @return 查询到的会员卡种类
     */
    @GetMapping("/info")
    public ResultInfo getCardTypeById(Integer cardTypeId){
        return fClientService.getCardTypeById(cardTypeId);
    }

    /**
     * 修改会员卡种类
     * @param cardType
     * @param price
     * @return
     */
    @PutMapping("/info")
    public ResultInfo updateCardType(String cardType, Integer price){
        CardType upCardType= JSONObject.parseObject(cardType,CardType.class);
        return fClientService.updateCardType(upCardType,price);
    }

    /**
     * 根据id删除用户
     * @param cardTypeId
     * @return
     */
    @DeleteMapping("/info")
    public ResultInfo deleteCardType(Integer cardTypeId){
        return fClientService.deleteCardType(cardTypeId);
    }

    /**
     * 添加会员卡种类和对应价格
     * @param cardType
     * @param price
     * @return
     */
    @PostMapping("/info")
    public ResultInfo addCardType(String cardType, Integer price){
        CardType addCardType = JSONObject.parseObject(cardType,CardType.class);
        return fClientService.newCardType(addCardType,price);
    }

    /**
     * 全查询
     * @return
     */
    @GetMapping("/all")
    public ResultInfo allCardType(){
        CardType cardType = new CardType();
        cardType.setDFlg(false);
        cardType.setStatu(true);
        return fClientService.getCardTypes(cardType);

    }
    /**
     * 查询每分钟价格
     */
    @GetMapping("/price")
    public ResultInfo allprice(){

        return fClientService.getPrice();
    }

    /**
     * 修改每分钟价格
     */
    @PutMapping("/priceinfo")
    public ResultInfo updataPrice(Integer amount){
        return fClientService.updatePrice(amount);
    }
}
